package com.test.springCloud.service.impl;

import com.test.springCloud.mapper.SessionListMapper;
import com.test.springCloud.service.SessionListService;
import com.test.springcloud.pojo.SessionListPojo;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("SessionListService")
public class SessionListServiceImpl implements SessionListService {
    @Resource
    SessionListMapper sessionListMapper;

    public int deleteByPrimaryKey(Integer id) {
        return sessionListMapper.deleteByPrimaryKey(id);
    }

    public int insert(SessionListPojo sessionList) {
        return sessionListMapper.insert(sessionList);
    }

    public SessionListPojo selectByPrimaryKey(Integer id) {
        return sessionListMapper.selectByPrimaryKey(id);
    }

    public List<Integer> selectUserIdByUserId(Integer id) {
        return sessionListMapper.selectUserIdByUserId(id);
    }

    public List<SessionListPojo> selectByUserId(Integer id) {
        return sessionListMapper.selectByUserId(id);
    }

    public Integer selectIdByUser(Integer fromId, Integer toId) {
        return sessionListMapper.selectIdByUser(fromId,toId);
    }

    public void addUnReadCount(Integer userId, Integer toUserId) {
        sessionListMapper.addUnReadCount(userId,toUserId);
    }

    public void delUnReadCount(Integer fromUserId, Integer toUserId) {
        sessionListMapper.delUnReadCount(fromUserId,toUserId);
    }

    //每半年删除一次数据
    @Scheduled(fixedRate = 1000 * 3600*24*31*6)
    public void autoDelSessionList() {
        sessionListMapper.autoDeldata();
    }
}
